home *** CD-ROM | disk | FTP | other *** search
/ Aminet 39 / Aminet 39 (2000)(Schatztruhe)[!][Oct 2000].iso / Aminet / dev / c / ExtrasLib.lha / ExtrasLib / Examples / Thread_Test / Test.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-07-17  |  1.5 KB  |  72 lines

  1. #define DEBUG
  2. #include <debug.h>
  3.  
  4.  
  5. #include <extras/threads.h>
  6. #include <clib/extras/thread_protos.h>
  7. #include <proto/intuition.h>
  8. #include <proto/exec.h>
  9. #include <proto/gadtools.h>
  10. #include <proto/graphics.h>
  11. #include <proto/diskfont.h>
  12. #include <proto/dos.h>
  13. #include <stdio.h>
  14. #include <exec/memory.h>
  15. #include <stdlib.h>
  16.  
  17. void __asm __saveds myMsgHandler(register __a0 struct Thread *T,
  18.                                  register __a1 struct ThreadMessage *Msg);
  19.  
  20. void main(void)
  21. {
  22.   struct MsgPort *mp;
  23.   struct Thread *t;
  24.   struct ThreadMessage m;
  25.   
  26.   if(mp=CreateMsgPort())
  27.   {
  28.     DKP("Starting Thread\n");
  29.     if(t=thread_StartThread(TA_MsgHandler,  myMsgHandler,
  30.                         0))
  31.     {
  32.       DKP("Thread Running\n");
  33.  
  34.       m.tm_Command=1;
  35.       m.tm_Msg.mn_ReplyPort=mp;
  36.       m.tm_Msg.mn_Length=sizeof(m);
  37.       
  38.       DKP("Putting a Message\n");
  39.       thread_PutTMsg(t, &m);
  40.       WaitPort(mp);
  41.  
  42.       DKP("Putting another Message\n");
  43.       m.tm_Command=20;
  44.       thread_PutTMsg(t, &m);
  45.       WaitPort(mp);
  46.       
  47.       DKP("Ending Thread\n");
  48.       thread_EndThread(t,0);
  49.     }
  50.     DeleteMsgPort(mp);
  51.   }
  52. }
  53.  
  54. void __asm __saveds myMsgHandler(register __a0 struct Thread *T,
  55.                                  register __a1 struct ThreadMessage *Msg)
  56. {
  57. //  printf("Msg Command=%d\n",Msg->tm_Command);
  58.  
  59.   switch(Msg->tm_Command)
  60.   {
  61.     case 1:
  62.       DKP("Command 1: Delay(120);");
  63.       Delay(60 * 2);
  64.       break;
  65.     case 20:
  66.       DKP("Command 20:\n");
  67.       break;
  68.   }      
  69.  
  70. //  ReplyMsg((struct Message *)Msg);
  71. }
  72.